<?php
/**
 *
 * @category   JND
 * @package    Jnd_View
 * @subpackage Helper
 * @copyright  Copyright (c) 2005-2009 DDB
 * @version    $Id: FormHiddenDisplay.php 16541 2009-10-12 17:02:30Z tbrouard $
 */
/**
 * Abstract class for extension
 */
require_once 'Zend/View/Helper/FormElement.php';
/**
 * Helper to generate a "hiddenDisplay" element
 *
 * @category   JND
 * @package    Jnd_View
 * @subpackage Helper
 */
class Jnd_View_Helper_FormHiddenDisplay extends Zend_View_Helper_FormElement
{

    /**
     * Generates a 'hidden' element.
     *
     * @access public
     *
     * @param string|array $name If a string, the element name.  If an
     * array, all other parameters are ignored, and the array elements
     * are extracted in place of added parameters.
     * @param mixed $value The element value.
     * @param array $attribs Attributes for the element tag.
     * @return string The element XHTML. div tag + input hidden tag
     */
    public function formHiddenDisplay($name, $value = null, array $attribs = null)
    {
        $info = $this->_getInfo($name, $value, $attribs);
        extract($info); // name, value, attribs, options, listsep, disable
        if (isset($id)) {
            if (isset($attribs) && is_array($attribs)) {
                $attribs['id'] = $id;
            } else {
                $attribs = array('id' => $id);
            }
        } else {
            $attribs['id'] = $name;
        }
        $display = (isset($attribs['display']) ? true : false);
        $class = (isset($attribs['class']) ? 'class="' . $attribs['class'] . '"' : "");
        $style = (isset($attribs['width']) ? 'width: ' . $attribs['width'] . ';' : "");
        $dn = $attribs['id'] . '_display';
        $style .= ($display ? "display: " . $attribs['display'] . ";" : "");
        $style = "style='$style'";
        $this->view->jQuery()->addOnLoad(
            '$("#' . $attribs['id'] . '").bind("change", function(){
      $("#' . $dn . '").html($("#' . $attribs['id'] . '").val());
      alert("' . $dn . ' - bordel !!!");
    });');
        $hidden = $this->_hidden($name, $value, $attribs);
        $div = '<div id="' . $dn . '" ' . $class . ' ' . $style . '>' . $value . '</div>' . ($display ? '<br clear="all" />' : "");
        return $div . $hidden;
    }
}
